/**
 * 列表初始化
 */
var DistributorPar = {
    id: "DistributorTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
DistributorPar.initColumn = function () {
    return [
        {title:'选择项',field: 'selectItem', radio: true},
        {title: '分销商ID', field: 'userId', visible: true, align: 'center', valign: 'middle'},
        {title: '姓名', field: 'shopName', visible: true, align: 'center', valign: 'middle'},
        {title: '电话', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '昵称', field: 'orderNo', visible: true, align: 'center', valign: 'middle'},
        {title: '状态', field: 'orderType', visible: true, align: 'center', valign: 'middle'},
        {title: '成为方式', field: 'orderStatus', visible: true, align: 'center', valign: 'middle'},
        {title: '可提现余额', field: 'price', visible: true, align: 'center', valign: 'middle'},
        {title: '等级', field: 'orderStatus', visible: true, align: 'center', valign: 'middle'},
        {title: '比例', field: 'price', visible: true, align: 'center', valign: 'middle'},
        {title: '发展分销商人数', field: 'settlementStatus', visible: true, align: 'center', valign: 'middle'},
        {title: '创建日期', field: 'settlementAt', visible: true, align: 'center', valign: 'middle'},
        {title: '审核日期', field: 'settlementAt', visible: true, align: 'center', valign: 'middle'},
        {title: '有效期开始日期', field: 'settlementAt', visible: true, align: 'center', valign: 'middle'},
        {title: '有效期到期日期', field: 'settlementAt', visible: true, align: 'center', valign: 'middle'},
        {title:"操作",field:'Button',events:operateEvents,formatter:DistributorPar.AddFunction}
    ];
};

DistributorPar.AddFunction = function(value,row,index){
    return [
            '<button id="confineMember" type="button" class="btn btn-primary">详情信息</button>&nbsp;' +
            '<button id="unConfineMember" type="button" class="btn btn-primary">充值/奖励</button>&nbsp;'+
            '<button id="unConfineMember" type="button" class="btn btn-primary">修改上级</button>&nbsp;'+
            '<button id="unConfineMember" type="button" class="btn btn-primary">下级推客</button>&nbsp;'+
            '<button id="unConfineMember" type="button" class="btn btn-primary">我的上级</button><br>'+
            '<button id="unConfineMember" type="button" class="btn btn-primary">分销订单记录</button>&nbsp;'+
            '<button id="unConfineMember" type="button" class="btn btn-primary">提现订单记录</button><br>'+
            '<button id="unConfineMember" type="button" class="btn btn-primary">1年佣金累计统计</button>&nbsp;&nbsp;'+
            '<button id="unConfineMember" type="button" class="btn btn-primary">1年提现累计统计</button>'
        ].join("");
}

window.operateEvents = {
    'click #confineMember':function (e,value,row,index) {
        DisMemberInfo.confineMembers(1,row['disUserId']);

    },
    'click #unConfineMember':function (e,value,row,index) {
        DisMemberInfo.confineMembers(0,row['disUserId']);

    },
}

/**
 * 检查是否选中
 */
DistributorPar.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        DistributorPar.seItem = selected[0];
        return true;
    }
};

/**
 * 查询列表
 */
DistributorPar.search = function () {
    //带参查询
    DistributorPar.table.refresh({query: DistributorPar.formParams()});
};
/**
 * 导出
 */
DistributorPar.export = function () {
    var ajax = new $ax(Feng.ctxPath + "/orderlist/selectListExport", function (data) {
        Feng.success("成功!");
    }, function (data) {
        Feng.error("失败!" + data.responseJSON.message + "!");
    });
    //带参导出
    ajax.set("id",$("#id").val());
    ajax.set("userId",$("#userId").val());
    ajax.set("beginTime",$("#beginTime").val());
    ajax.set("endTime",$("#endTime").val());
    ajax.start();
};

//表单参数
DistributorPar.formParams = function() {
    var queryData = {};
    queryData['id'] = $("#id").val();
    queryData['userId'] = $("#userId").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
}

//在整个页面加载的时候
$(function () {
    //获取列表数据
    var defaultColunms = DistributorPar.initColumn();
    var table = new BSTable(DistributorPar.id, "/distributorlist/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(DistributorPar.formParams());
    DistributorPar.table = table.init();
});
